<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/head.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理工作平台</title>
<script type="text/javascript" src="<%=basePath%>/js/check.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/jquery.cascade.1.1.1/jquery.cascade.js"></script>            
<script type="text/javascript" src="<%=basePath%>/js/jquery.cascade.1.1.1/jquery.cascade.ext.js"></script> 
<script type="text/javascript" src="<%=basePath%>/js/jquery.cascade.1.1.1/jquery.templating.js"></script> 
<script type="text/javascript" src="<%=basePath%>/js/json2.min.js"></script>
<script type="text/javascript">
var list1 = "";
</script>
<style type="text/css">
.cascade-loading  	
{																		
	background: transparent url("indicator.gif") no-repeat center; 					
}
</style>
</head>
<body>
<form action="" name="form1" id="form1">
  	<table>
  		<tr>
  			<td>功能名称:</td>
  			<td><input type="text" name="function.functionname" id="functionname" value="<s:property value="function.functionname"/>"/></td>
  		</tr>
  		<tr>
  			<td></td>
  			<td><span id="accountmessage"></span></td>
  		</tr>
  		<tr>
  			<td>上级功能名称:</td>
  			<td>
			<select id="simple"  name="function.parentid" >
				<s:iterator value="list">
					<s:if test="parentid==0">
					<option value="<s:property value="id"/>"><s:property value="functionname"/></option>
					</s:if>
					<s:else>
					<script type="text/javascript">
					list1 += "{\"When\":\"<s:property value="parentid"/>\",\"Value\":\"<s:property value="id"/>\",\"Text\":\"<s:property value="functionname"/>\"},";
					</script>
					</s:else>
				</s:iterator>
			</select>
			<select id="simple_child" name="sub_id">
				<option value='nope1'>请选择上级功能</option>
			</select>
  			</td>
  		</tr>
  		<tr>
  			<td>U　R　L :</td>
  			<td><input type="text" name="function.url" id="url"  value="<s:property value="function.url"/>"/></td>
  		</tr>
  		<tr>
  			<td>图　　标:</td>
  			<td><input type="text" name="function.image" id="image"  value="<s:property value="function.image"/>"/></td>
  		</tr>
  		<tr>
  			<td>备　　注:</td>
  			<td><textarea type="text" name="function.des" id="des"><s:property value="function.des"/></textarea></td>
  		</tr>
  		<tr>
  		<td colspan="2" align="center">
  			<input type="button" value="提交" id="subform"/>&nbsp;&nbsp;<input type="reset" value="重置"/></td>
  		</tr>
  	</table>
  	<input type="hidden" name="functionid" id="functionid" value="<s:property value="function.id"/>"/>
  	</form>
  	</body>
</html>

<script type="text/javascript">
<!--
$("#subform").click(function(){
	var content = "";
	var murl = "";
	var functionname = $("#functionname").val();
	var functionid = $("#functionid").val();
	var image = $("#image").val();
	var des = $("#des").val();
	var url = $("#url").val();
	
	if(functionname =="" || accountflag==1){
		alert("功能名称为空或已经存在");
		return false;
	}
	if(url ==""){
		alert("URL不能为空");
		return false;
	}
		murl = "savefunction.do";
	//序 列化表格元素 (类似 '.serialize()' 方法) 返回 JSON 数据结构数据
	content = $("#form1").serializeArray();
	//alert(content);
	$.post(murl,content,function(data){
		if(data==1){
			alert("保存失败！");
		}else{
			alert("保存成功！");
		}
		location="functionlist.do";
	},"json");
});

/**
 * 检查帐号是否存在
 */
var accountflag = 0;
$("#functionname").blur(function (){
	var functionname = $("#functionname").val();
	if(functionname == ""){
		$("#accountmessage").html("");
		$("#accountmessage").html("帐号不能为空");
		return false;
	}
	$.getJSON("checkfunctionname.do",{functionname:functionname},function(data){
		if(data==1){
			$("#accountmessage").html("");
			$("#accountmessage").html("帐号已经存在，请重新填写帐号");
			accountflag = 1;
		}else{
			accountflag = 0;
			$("#accountmessage").html("");
			$("#accountmessage").html("帐号不存在，可以添加");
		}
	});
});

	function commonTemplate(item) {
		return "<option value='" + item.Value + "'>" + item.Text + "</option>"; 
	};
	
	function commonMatch(selectedValue) {
		return this.When == selectedValue; 
	};//JSON.parse(list1)

	$(function() {
		if(list1.lastIndexOf(",") != -1)
			list1 = list1.substring(0,list1.length -1);		
		list1 = "["+list1+"]";
		list1 = JSON.parse(list1);
		//级联方法
		jQuery("#simple_child").cascade("#simple", {
			list : list1,
			template : commonTemplate,
			match : commonMatch
		});
	});
	//-->
</script>



